package crm.view.Admin;

import crm.entity.Customer;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.util.List;
import java.util.Vector;

public class CustomProducts extends JFrame{

    public CustomProducts(List<Customer> list) {
        Vector<Vector<Object>> vectordata=new Vector<>();

        for(Customer customer:list){
            Vector<Object> objs=new Vector<>();
            objs.add(customer.getProducts());
            objs.add(customer.getProduct_id());
            objs.add(customer.getConsume_time());
            objs.add(customer.getProduct_type());
            objs.add(customer.getPrice());
            vectordata.add(objs);
        }

        String[] labels={"产品名称","产品编号","生产日期","产品类型","价格"};

        Vector<String> columnNames=new Vector<>();
        for(String label:labels){
            columnNames.add(label);
        }

        JTable table=new JTable(vectordata, columnNames);
        JScrollPane scrollPane = new JScrollPane(table);

        this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

        JPanel panel = new JPanel();
        panel.setLayout(null);
        panel.setBorder(new TitledBorder(null, "", TitledBorder.LEADING,
                TitledBorder.TOP, null, null));

        this.getContentPane().add(panel);

        panel.add(scrollPane);
        scrollPane.setBounds(15, 15, 500, 400);
        scrollPane.setBorder(new TitledBorder(null, "客户所购产品信息",
                TitledBorder.LEADING, TitledBorder.TOP, null, null));
        this.setSize(620, 500);

        this.setTitle("查询客户所购产品信息");
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }
}
